package main.java.dao.impl;

import main.java.dao.BaseDAO;
import main.java.dao.PatientDao;
import main.java.polo.Patient;

import java.util.Collections;
import java.util.List;

public class PatientDaoImpl extends BaseDAO implements PatientDao {
    @Override
    public List<Patient> selectAll() {
        try {
            String sql = "select patient_id patientId ,patient_name patientName ," +
                    "patient_record patientRecord ,patient_history patientHistory from t_patient";
            return executeQuery(Patient.class, sql,null);
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    @Override
    public int insert(Patient patient) {
        try {
            String sql = "insert into t_patient (patient_name,patient_record,patient_history) values (?,?,?)";
            return executeUpdate(sql,patient.getPatientName(),patient.getPatientRecord(),patient.getPatientHistory());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public int delete(Integer patientId) {
        try{
            String sql = "delete from t_patient where patient_id = ?";
            return executeUpdate(sql,patientId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
